<?php
class Pembayaran_bebas_model extends CI_Model 
{

	function __construct()
	{
		parent::__construct();
	}
	
	function insert_data($id_komponen,$nominal,$nis){
		$tgl=date('Y-m-d');
		$data=array('tgl_bayar'=>$tgl,
					'nis'=>$nis,
					'id_komponen'=>$id_komponen,
					'nominal'=>$nominal);
		$insert=$this->db->insert('pembayaran_bebas',$data);
		return $insert;
	}
	
	function delete($id){
		$this->db->where('id', $id);
		$delete = $this->db->delete('pembayaran_bebas');
		return $delete;
	}

	
	function get_history($nis){
		$sql="select a.*,b.nama_komp from pembayaran_bebas a left join mr_komp_pembayaran b on a.id_komponen=b.id_komp
				where a.nis='".$nis."'";
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_bayar_bulan($nis,$id_komp,$tgl_awal,$tgl_akhir){
		$sql="select IFNULL(SUM(nominal),0) as total from pembayaran_bebas 
			where nis='".$nis."' and id_komponen='".$id_komp."'  
			and tgl_bayar between '".$tgl_awal."' and '".$tgl_akhir."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			$hasil= $query->row_array();
			return $hasil['total'];
		}else{
			return 0;
		}
	}
	
	
}

?>